// 封装分类数据业务相关
import { getCategoryAPI } from "@/api/category";
import { onMounted, ref, watch } from "vue";
import { useRoute } from "vue-router";
export function useCategory() {
  const categoryData = ref({});
  const route = useRoute();
  const getCategory = async () => {
    const res = await getCategoryAPI(route.params.id);
    // console.log(res);
    categoryData.value = res.result;
  };
  // 挂载后执行getCategory函数
  onMounted(() => getCategory());
  // 监听路由变化,如果变化则执行getCategory函数
  watch(route, () => getCategory());

  return {
    categoryData
  }
}